package com.jvm.memory;

/**
 * Finlize的作用一字之星  及可达性分析两次标记
 *
 * @author Lizhong
 * @date 2019/2/20
 */
public class FinalizeGC {
    static Obj obj = null;

    public static void main(String[] args) throws InterruptedException {
        obj = new Obj();
        obj = null;
        System.gc();
        Thread.sleep(1500);// finalize 优先级低
        System.out.println(obj);
        obj = null;
        Thread.sleep(1500);// finalize 优先级低
        System.out.println(obj);

    }
}

class Obj {
    static Obj obj = null;

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("被拯救");
        FinalizeGC.obj = this;
    }
}
